<?php

/**
 * RP System
 *
 * @version 1.0
 * @copyright 2004 Ron Planken
 */

class shout {
	function get($shout_id = 0) {

		global $dbh;

		if ($shout_id == 0) {
			$query ="SELECT shout_id
						   ,shouts.player_id
						   ,shouts.date_time_posted
						   ,shouts.shout_text
						   ,name
					   FROM shouts
				 INNER JOIN player
						 ON shouts.player_id = player.player_id
				   ORDER BY date_time_posted DESC
				   	  LIMIT 0,30
							";
		} else {
			$query ="SELECT shout_id
						   ,shouts.player_id
						   ,shouts.date_time_posted
						   ,shouts.shout_text
						   ,name
					   FROM shouts
				 INNER JOIN player
						 ON shouts.player_id = player.player_id
					  WHERE news_id = $shout_id
							";
		}
		$shoutItems = selectMultiQuery($query, $dbh);

		return $shoutItems;
	}

	function save($shout_id = 0, $player_id = 0, $date_time_posted = "", $shout_text = "") {

		global $dbh;

		$player_id = secure_int($player_id);
		$shout_text = secure_string($shout_text);

		if ($shout_id == 0) {

			$shout_id = secure_int($shout_id);

			$query ="INSERT INTO shouts
						   (player_id
						   ,date_time_posted
						   ,shout_text)
					VALUES ($player_id
						   ,$date_time_posted
						   ,$shout_text)
							";
			$status = InsertQuery($query, $dbh);
		} else {
			$query ="UPDATE shouts
						SET player_id = $player_id
						   ,date_time_posted = $date_time_posted
						   ,shout_text = $shout_text
					  WHERE shout_id = $shout_id
							";
			$status = UpdateQuery($query, $dbh);
		}

		return $status;

	}
	

	function remove($shout_id = 0) {

		global $dbh;
		
		$shout_id = secure_int($shout_id);
		
		$query ="DELETE FROM shouts
				  	   WHERE shout_id = $shout_id;
							";
		$status = UpdateQuery($query, $dbh);


		
		return $status;
	}
	
}
?>